<template>
	<div class="back-top" v-show="show" v-on:click="toTop">
		回到顶部
	</div>
</template>

<script>
    export default {
      data() {
          return {
          	show: false
          };
      },
      beforeMount() {
      	window.onscroll = () => {
      		if(document.body.scrollTop > 400){
      			this.show = true;
      		}else{
      			this.show = false;
      		};
      	}
      },
      beforeDestroy(){
      	window.onscroll = null;
      },
      methods: {
      	toTop(){
      		document.body.scrollTop = 0;
      	}
      }
    };
</script>

<style lang='scss' scoped>
	.back-top{
		width: 16px;
		padding: 8px 5px;
		position: fixed;
		bottom:100px;
		right: 0px;
		background-color: #fff;
		border-radius: 5px;
	}
</style>